#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "MessageRouter.h"
#include "WString.h"
#include "mock/LoggerMock.h"
#include "mock/ServiceMock.h"
#include "mock/ArduinoMock.h"
using ::testing::ReturnRef;

class MessageRouterTest : public ::testing::Test {
public:
	MessageRouterTest() : m(logger), s(a, m, logger), s1(a, m, logger) {}
protected:
	ArduinoMock a;
	LoggerMock logger;
	MessageRouter m;
	ServiceMock s, s1;

	virtual void SetUp() {
		m.addService(s);
		m.addService(s1);
	}
};


TEST_F(MessageRouterTest, postMessage){

	EXPECT_CALL(s, onMessage(String("Test")))
		.Times(1);
	
	m.postMessage(s1, "Test");
}

TEST_F(MessageRouterTest, avoidDouleAddingofService){
	m.addService(s);
	EXPECT_CALL(s, onMessage(String("Test")))
		.Times(1);
	m.postMessage(s1, "Test");
}

TEST_F(MessageRouterTest, broadcastMessage){
	EXPECT_CALL(s, onMessage(String("Test")))
		.Times(1);
	EXPECT_CALL(s1, onMessage(String("Test")))
		.Times(1);
	
	m.broadcastMessage("Test");
}

TEST_F(MessageRouterTest, removeSerice){
	m.addService(s);
	EXPECT_CALL(s, onMessage(String("Test")))
		.Times(1);
	m.postMessage(s1, "Test");
	EXPECT_CALL(s, getName())
		.Times(1).
		WillOnce(Return("Service"));
	
	m.removeService("Service");
	m.postMessage(s1, "Test");
}

TEST_F(MessageRouterTest, removeUnknownSerice){
	//TODO
	//ASSERT_EQ(
	//m.removeService("UnknownService");//, 0);
}